package com.yanqu.road.dao.impl.activity.cricket;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.tongbing.config.TongBingBuffTypeConfig;
import com.yanqu.road.entity.cricket.config.CricketRankConfig;
import com.yanqu.road.utils.date.DateHelper;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CricketRankConfigDaoImpl extends TempDao {

    private static String selectSQL = "select * from `t_s_activity_cricket_rank` where `activityId`=?";

    public Map<Integer, CricketRankConfig> getDataMap(int activityId) {
        Map<Integer, CricketRankConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(selectSQL);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                CricketRankConfig data = new CricketRankConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setBigTitle(rs.getInt("bigTitle"));
                data.setStar(rs.getInt("star"));
                data.setName(rs.getString("name"));
                data.setRankScore(rs.getInt("rankScore"));
                data.setMatchRange(rs.getString("matchRange"));
                data.setAttackerPoint(rs.getString("attackerPoint"));
                data.setDefendPoint(rs.getString("defenPoint"));
                data.setEndReset(rs.getInt("endReset"));
                data.setReward(rs.getString("reward"));
                map.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
